package com.gin.custom.cust2;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gin.custom.R;

public class TestAdapter extends RecyclerView.Adapter<TestAdapter.Holder> {
    public static final String[] EVENTS_NAMES = new String[]{"元始天尊", "灵宝天尊", "道德天尊", "东方安宝华林青灵始老君", "南方梵宝昌阳丹灵真老君", "中央玉宝元灵元老君", "西方七宝金门皓灵皇老君", "北方洞阴朔单郁绝五灵玄老君", "上：玉皇大帝", "北：中天紫微北极大帝", "西：勾陈上宫天皇大帝", "南：南极长生大帝", "下：承天效法后土皇地祗", "东：东极青华大帝", "西王母", "东王公", "天官（赐福）", "地官（赦罪）", "水官（解厄）", "东方玉宝皇上天尊", "南方玄真万福天尊", "西方太妙至极天尊", "北方玄上玉宸天尊", "东北方度仙上圣天尊", "东南方好生度命天尊", "西南方太灵虚皇天尊", "西北方无量太华天尊", "上方玉虚明皇天尊", "下方真皇洞神天尊"};
    String[] datas = EVENTS_NAMES;
    private OnItemClickListener mOnItemClickListener = null;

    public TestAdapter() {
        datas = EVENTS_NAMES;
    }

    public TestAdapter(String[] datas) {
        this.datas = datas;
    }

    @Override
    public TestAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_test, parent, false));
    }

    @Override
    public void onBindViewHolder(TestAdapter.Holder holder, final int position) {
//        LogUtils.i("-------------" + datas[position]);
        holder.tvText.setText(datas[position]);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(v, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.length;
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    //define interface
    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    class Holder extends RecyclerView.ViewHolder {

        private TextView tvText;

        public Holder(View itemView) {
            super(itemView);
            tvText = itemView.findViewById(R.id.text);
        }
    }
}